home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 18 / CU Amiga Magazine's Super CD-ROM 18 (1997)(EMAP Images)(GB)[!][issue 1998-01].iso / C / MakeIndex.0 < prev    next >
Text File  |  1997-11-20  |  6KB  |  182 lines

  1. /* MakeIndex
  2.     Hacked by Andy Macklin to produce a sort of index of doc/guide files.
  3.     My version of grep uses the following syntax...
  4.     usage: grep [-[[AB] ]<num>] [-[CEFGVchilnqsvwx]] [-[ef]] <expr> [<files...>]
  5.  
  6.         Requirements:   grep
  7.                         sort
  8.                         copy
  9.                         searchguide (optional)
  10.                         same syntax as buildindex  (optional)
  11.  
  12. */
  13.  
  14. buildidx='Y' /*Change to 'Y' for an all in one script ;) */
  15. SGUIDE='N'   /*Change to 'Y' for an automatic search button in the docs guide file */
  16.  
  17. address command
  18.  
  19. Volume = left(pragma('D'),pos(':',pragma('D')))
  20.  
  21. /* Clear icon position */
  22. 'nopos' Volume'disk nodd'
  23.  
  24. /* defines and such */
  25.         /* GREP CALL */
  26. GREPCALL = "grep"
  27.         /* GREP HELP CALL */
  28. GREPHELP = "grep -h"
  29.         /* Where's the CUCD index? */
  30. IDXLOC = Volume'CDsupport/CUCD.index'
  31.         /* Where's the finished guide to go to?*/
  32. outfile = Volume'CDsupport/Docs.guide'
  33.         /* Path to MultiView */
  34. MView = Volume'Utilities/MultiView'
  35.         /* Extensions to search for */
  36. Extensions = 'guide|doc|dok|txt|text|asc|man|readme'
  37.  
  38. if buildidx='Y' then do
  39.     /* NB the column format is important for the sort fuction later */
  40.     'delete >NIL:' outfile    /* Otherwise the guide will contain a reference to itself */
  41.     'list' Volume'CUCD all files pat=~(#?.info) lformat "%-33N%P%N" to' IDXLOC
  42.     end
  43.  
  44. grepfile = "t:grepoutput." || Pragma("i")
  45. agfile = "t:grepguide." || Pragma("i")
  46. CR      = d2c(10)
  47. TAB     = d2c(9)
  48.  
  49. /* setup the output file - we need this first so we can show errors in it */
  50. IF Open(agfp,agfile,'w') = 0 THEN DO
  51.         SAY "Couldn't create amigaguide file ("||agfile||")"
  52.         EXIT 20
  53.         END
  54.  
  55. call writeln(agfp,'@DATABASE "CD docs"')
  56. call writeln(agfp,'@REMARK created by Andys MakeIndex v2 :)')
  57. call writeln(agfp,'')
  58. call writeln(agfp,'@NODE Main "DOCS & GUIDES"')
  59. call writeln(agfp,'')
  60.  
  61. /* Put a search button (needs searchguide in the CDs path) */
  62. if SGUIDE='Y' then do
  63. call writeln(agfp,'@{" Search " SYSTEM "RUN SearchGuide '||substr(outfile,pos(':',outfile)+1)||'" }')
  64. call writeln(agfp,'')
  65. end
  66.  
  67. SIGNAL ON FAILURE
  68. ADDRESS COMMAND
  69. 'delete >NIL:' grepfile
  70. do until Extensions = ''
  71.     parse var Extensions ext '|' Extensions
  72.     GREPCALL '-F .'ext IDXLOC '>>' grepfile
  73.     end
  74. 'rename' grepfile ' to ' grepfile||'.old'
  75. 'sort' grepfile||'.old' grepfile 'colstart 37'
  76. SIGNAL OFF FAILURE
  77.  
  78. IF Open(grepfp,grepfile,'r') = 0 THEN DO
  79.         CALL HandleError("Couldn't open grep output file ("||grepfile||")","")
  80.         END
  81.  
  82. /*************************************************************************
  83. **  Format of Grep output
  84. **  =====================
  85. **
  86. **HTMLit!.guide                 CUCD4:Magazine/WiredWorld/HTMLit!/HTMLit!.guide
  87. **DemosOfTheWorld.guide         CUCD4:CUCD/Demos/DemosOfTheWorld/DemosOfTheWorld.guide
  88. **mc12.guide                    CUCD4:CUCD/Demos/Malevolent_Creations/mc12.guide
  89. **iml-Feb71.guide               CUCD4:CUCD/Graphics/Imagine/iml-Feb71.guide
  90. **Dust.guide                    CUCD4:CUCD/Graphics/Imagine/Dust/Docs/Dust.guide
  91. **DustEnglish.guide             CUCD4:CUCD/Graphics/Imagine/Dust/Docs/DustEnglish.guide
  92. **IM_Organizer.guide            CUCD4:CUCD/Graphics/Imagine/IM_Organiser/IM_Organizer.guide
  93. **TextureStudio.guide           CUCD4:CUCD/Graphics/Imagine/TextureStudio/Docs/TextureStudio.guide
  94. **ncFTPevents.guide             CUCD4:CUCD/Online/ThorStuff/Programs/ncFTPevents/Thor/docs/ncFTPevents.guide
  95. **
  96. ****************************************************************************/
  97.  
  98. line = ReadLn(grepfp)
  99. IF EOF(grepfp) THEN DO
  100.         call close(grepfp)
  101.         say 'No files found'
  102.         exit 10
  103.         END
  104.  
  105.  
  106.         CALL Pragma('W','n')            /* turn off dos requesters */
  107.  
  108. DO WHILE ~EOF(grepfp)
  109.         /* START BY LOOKING FOR FILENAMES */
  110.         currentfile = Strip(Left(line,Length(Word(line,1))),"B")
  111.         location = strip(right(line,length(line)-length(word(line,1))),"B")
  112.         if right(currentfile,5) ='guide' then
  113.         do
  114.             node='/main'
  115.             action='link "'
  116.         end
  117.         else
  118.         do
  119.             node=''
  120.             action='system "'MView' '
  121.         end
  122.         endif
  123.         call writeln(agfp,'@{" 'currentfile left('',33-length(currentfile))' "' action||location||node'" }   'substr(location,pos(':',location)+1))
  124.         line = ReadLn(grepfp)
  125.                 END
  126.  
  127. call WriteLn(agfp,'@ENDNODE')
  128.  
  129. call Close(grepfp)
  130. call Close(agfp)
  131.  
  132.        CALL Pragma('W','w')            /* turn dos requesters back on */
  133.  
  134. address command
  135. 'copy' agfile outfile
  136. 'delete >NIL:' grepfile
  137. 'delete >NIL:' grepfile||'.old'
  138. 'delete >NIL:' agfile
  139.  
  140. EXIT
  141.  
  142. FAILURE:
  143. ERROR:
  144.         errRC = RC
  145.         CALL Close(grepfp)
  146.         CALL HandleError("Grep Failure:"|| CR || "    " || FullCommand ,grepfile)
  147.         EXIT
  148.  
  149. /***************************************************/
  150. HandleError: PROCEDURE EXPOSE agfp grepfile agfile grephelp
  151.  
  152.         ErrorText = arg(1)
  153.         ErrorFile = arg(2)
  154.  
  155.         call writeln(agfp,'-=-=-=-=-=-=-=-=-=  E R R O R  =-=-=-=-=-=-=-=-=-')
  156.         call writeln(agfp,ErrorText)
  157.         call writeln(agfp,' ')
  158.  
  159.         IF (ErrorFile~="" & Exists(ErrorFile)) THEN DO
  160.                 call writeln(agfp,"Response:")
  161.                 ADDRESS COMMAND GREPHELP '>>'ErrorFile
  162.                 Open('errorfp',ErrorFile,'r')
  163.                 DO WHILE ~EOF('errorfp')
  164.                         call writeln(agfp,"    " || ReadLn('errorfp'))
  165.                         END
  166.                 call close('errorfp')
  167.                 END
  168.  
  169.         call writeln(agfp,"")
  170.         call writeln(agfp,"Current Path:")
  171.         call writeln(agfp,"    "||Pragma("D"))
  172.         call writeln(agfp,'@ENDNODE')
  173.  
  174.         call close(agfp)
  175.  
  176.         IF Exists(grepfile) THEN Delete(grepfile)
  177.         Delete(agfile)
  178.  
  179.         EXIT 20
  180. RETURN
  181.  
  182.